<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_query = new WP_Query([
    'post_type' => 'post',
    'posts_per_page' => 50,
    'post_status' => 'publish',
    'paged' => $paged
]);

if($posts_query->have_posts()){ ?>
    <div class="container">
        <h1 class="my-5 text-center">全部资源表</h1>
    <table class="table table-bordered table-striped">
    <thead>
        <th>序号</th>
        <th>资源名称</th>
        <th>最新版本</th>
        <th>类型</th>
        <th>前端演示网址</th>
        <th>后台演示网址</th>
        <th>使用教程网址</th>
    </thead>
        <tbody>
    <?php
    $index = 0;
    while($posts_query->have_posts()){
        $posts_query->the_post();
        $name = get_the_title();
        $permalink = get_the_permalink();
        $index++;
        $theme_version_histories = get_post_meta(get_the_ID(), "cao_downurl_new", true);

        ?>
        <tr>
            <td><?php echo $index;?></td>
            <td><a href="<?php echo $permalink;?>"><?php echo $name;?></a></td>
            <td><?php echo $theme_version_histories[0]['version']??'';?></td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
        </tr>
    <?php
    }
    ?></tbody>
    </table></div>
<?php
    // Pagination
    echo '<div class="pagination">';
    echo paginate_links(array(
        'total' => $posts_query->max_num_pages,
        'current' => $paged,
        'prev_text' => '&laquo; Previous',
        'next_text' => 'Next &raquo;'
    ));
    echo '</div>';
}

wp_reset_postdata();